<template>
  <el-config-provider :locale="currentLocale">
    <router-view />
  </el-config-provider>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { ElConfigProvider } from "element-plus";
// import zhCn from "element-plus/lib/locale/lang/zh-cn";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import { getUserInfo, getUserRegions } from "@/api/user";
import { useUserStoreHook } from "@/store/modules/user";
import { getToken } from "@/utils/auth";
const userStroe = useUserStoreHook();

export default defineComponent({
  name: "app",
  components: {
    [ElConfigProvider.name]: ElConfigProvider
  },
  computed: {
    currentLocale() {
      return zhCn;
    }
  },

  mounted: async () => {
    const token = getToken();
    // console.log("token:", token);
    if (token && token.accessToken) {
      const userInfoRes = await getUserInfo();
      // 获取用户能够查看的地区数据范围
      if (userInfoRes.user) {
        userStroe.SET_USERINFO(userInfoRes);
        const userRegionsRes = await getUserRegions(userInfoRes.user);
        userStroe.SET_USERREGIONS(userRegionsRes);
      }
    }
  }
  // Generate a random number between 1 and 10
});
</script>
